﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>职称设置</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <script src="https://unpkg.com/element-plus/dist/index.full.min.js"></script>
    <style>
        .content-container {
            padding: 20px;
            background-color: #f5f7fa;
            border-radius: 4px;
            margin: 10px;
        }

        body {
            background-color: #FFFFCC; /* 示例浅灰色，可替换为你的图片主色值 */
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .breadcrumb {
            font-size: 14px;
            color: #606266;
        }

        .el-table {
            margin-top: 10px;
        }

        .button-container {
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>您正在做的业务是：人力资源--客户化设置--人力资源档案管理设置--职位设置</div>
        <div class="button-container">
            <el-button type="primary" v-on:click="goToAddPage">添加</el-button>
        </div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="major_kind_id" label="职位分类编号" width="180"></el-table-column>
            <el-table-column prop="major_kind_name" label="职位分类名称" width="180"></el-table-column>
            <el-table-column prop="major_id" label="职位编号" width="180"></el-table-column>
            <el-table-column prop="major_name" label="职位名称" width="180"></el-table-column>
            <el-table-column label="操作" width="180">
                <template #default="scope">
                    <el-button type="button" v-on:click="confirmDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <script>
        const { createApp, ref } = Vue;

        const app = createApp({
          setup() {
              const tableData = ref([]);

              // 获取职称数据
              // const fetchTitles = async () => {
              //     try {
              //         const response = await axios.get('ZWSZ/GetTitles');
              //         tableData.value = response.data;
              //         console.log('职称数据加载成功:', tableData.value);
              //     } catch (error) {
              //         console.error('获取职称数据失败:', error);
              //         ElementPlus.ElMessage.error('加载职称数据失败，请重试');
              //     }
              // };

              function fill(){
                      axios.get('/ZWSZ/GetTitles')
                      .then(res => {
                    console.info(res.data);
                    tableData.value = res.data.list;
                }).catch(err => {
                    console.info(err)
                })
              }
              fill();
              // 确认删除对话框
              const confirmDelete = (row) => {
                  ElementPlus.ElMessageBox.confirm(
                      `确定要删除职称 "${row.major_name}" 吗？`,
                      '删除确认',
                      {
                          confirmButtonText: '确认删除',
                          cancelButtonText: '取消',
                          type: 'warning',
                      }
                  )
                  .then(() => {
                      // 用户点击确认，执行删除操作
                      deleteTitle(row);
                  })
                  .catch(() => {
                      // 用户点击取消，不执行任何操作
                      ElementPlus.ElMessage.info('已取消删除');
                  });
              };

              // 删除职称（需后端配合实现）
              // const deleteTitle = async (row) => {
              //     try {
              //         const response = await axios.delete(`ZWSZ/Delete/${row.mak_id}`);
              //         if(response.data > 0){
              //             console.log("删除成功");
              //             fetchTitles();
              //             ElementPlus.ElMessage.success('删除成功');
              //         } else {
              //             console.log("删除失败");
              //             ElementPlus.ElMessage.error('删除失败，请重试');
              //         }
              //     } catch (error) {
              //         console.error('删除职称失败:', error);
              //         ElementPlus.ElMessage.error('删除职称失败，请重试');
              //     }
              // };

              function deleteTitle(row){
                    console.info(row.mak_id);
                    axios.delete(`/ZWSZ/Delete/${row.mak_id}`)
                      .then(res => {
                          console.info(res.data);
                          if(res.data.zhi>0){
                            fill();
                            ElementPlus.ElMessage.success('删除成功');
                          }else{
                              ElementPlus.ElMessage.error('删除失败，请重试');
                          }

                      }).catch(err => {
                          console.info(err)
                      })
                }

              

              const goToAddPage = () => {
                  window.location.href = '/ZWSZ/Add';
              };

              return {
                  tableData,
                  // fetchTitles,
                  confirmDelete,
                  deleteTitle,
                  goToAddPage
              }
          }
        });

        app.use(ElementPlus);
        app.mount('#app');
    </script>
</body>
</html>